package com.hpu.parser;

import com.hpu.bean.Score;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

/**
 * 期末成绩解析器
 * 
 * @author Administrator
 * 
 */
public class ScoreParser {

	public List<Score> parse(String parseString) {
		System.out.println(parseString);
		List<Score> scoreList = new ArrayList<>();
		try {
			JSONArray array = new JSONArray(parseString);

			for (int i = 0; i < array.length(); i++) {
				JSONArray array2 = array.getJSONArray(i);
				String credit = array2.getString(4);
				String subject = array2.getString(2);
				String number = array2.getString(0);
				String order = array2.getString(1);
				String value = array2.getString(9).length() == 0 ? "--" : array2.getString(9);
				String valueOrder = array2.getString(10).length() == 0 ? "--" : array2.getString(10);
				
				scoreList.add(new Score(credit, subject, "本学期", number, order, value,valueOrder));
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}
		return scoreList;
	}
}
